//
//  RHDataTypeItemCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/7/27.
//

#import "RHDataTypeItemCell.h"
#import "RHDeviceTypeCircleView.h"
#import "RHTools.h"
@interface RHDataTypeItemCell()

@property(nonatomic,strong)QMUILabel *nameLab;
@property(nonatomic,strong)QMUILabel *countLab;
@property(nonatomic,strong)RHDeviceTypeCircleView *circleView;
@end
@implementation RHDataTypeItemCell
- (instancetype)initWithCoder:(NSCoder *)coder
{
    return [super initWithCoder:coder];
}
-(instancetype)init
{
    return  [super init];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
-(void)setupUI{
    
    _circleView = [[RHDeviceTypeCircleView alloc]init];
    [self.contentView addSubview:_circleView];
    
    QMUILabel *nameLab = [[QMUILabel alloc]init];
    [self.contentView addSubview:nameLab];
    nameLab.numberOfLines = 0;
    nameLab.font = [UIFont systemFontOfSize:11];
    nameLab.textAlignment = NSTextAlignmentCenter;
    nameLab.textColor = [UIColor colorWithHexString:@"6C757D"];
    nameLab.text = @"--";
    self.nameLab = nameLab;
    
    QMUILabel *countLab = [[QMUILabel alloc]init];
    [self.contentView addSubview:countLab];
    countLab.textAlignment = NSTextAlignmentCenter;
    countLab.textColor = [UIColor colorWithHexString:@"3F4443"];
    countLab.font = [UIFont systemFontOfSize:14];
    countLab.text = @"-";
    self.countLab = countLab;
    
    kWeakSelf;
    [countLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.circleView);
        make.centerY.equalTo(weakSelf.circleView);
    }];
    [_circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.contentView);
        make.top.equalTo(weakSelf.contentView).offset(kScaleW(5));
//        make.bottom.equalTo(nameLab.mas_top).offset(-kScaleW(3));
        make.height.offset(kScaleW(50));
        make.width.equalTo(weakSelf.circleView.mas_height);
    }];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).offset(0);
        make.right.equalTo(weakSelf.contentView).offset(0);
        make.top.equalTo(weakSelf.circleView.mas_bottom).offset(3);
//        make.bottom.equalTo(weakSelf.contentView).offset(-2);
        make.height.greaterThanOrEqualTo(@(20));
    }];
    
}
-(void)setData:(RHDeviceTypeModel *)data
{
//    self.nameLab.text = [RHTools changeDevType:ValidNullDataToString(data.productTypeCode, @"--")];
    self.nameLab.text = ValidNullDataToString(data.productTypeName, @"--");
    self.countLab.text = [NSString stringWithFormat:@"%ld",(long)data.deviceNumber];

    self.circleView.percent = data.percent;
    self.circleView.randomAngle = self.randomAngle;
    
    if(data.deviceNumber >9999){
        self.countLab.font = [UIFont systemFontOfSize:11];
    }else if(data.deviceNumber >999){
        self.countLab.font = [UIFont systemFontOfSize:12];
    }else{
        self.countLab.font = [UIFont systemFontOfSize:14];
    }
    
}
-(void)setColor1:(UIColor *)color1
{
    _color1 = color1;
    self.circleView.color1 = _color1;
}
-(void)setColor2:(UIColor *)color2
{
    _color2 = color2;
    self.circleView.color2 = _color2;
}


@end
